package org.jeecg.modules.controller.market;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.util.*;
import java.util.stream.Collectors;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import lombok.Data;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.entity.DbContract;
import org.jeecg.modules.entity.DbFile;
import org.jeecg.modules.entity.DbPurpose;
import org.jeecg.modules.entity.vo.DbPurposeVo;
import org.jeecg.modules.service.IDbFileService;
import org.jeecg.modules.service.IDbPurposeService;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.def.NormalExcelConstants;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.view.JeecgEntityExcelView;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;

 /**
 * @Description: db_purpose
 * @Author: jeecg-boot
 * @Date:   2024-06-13
 * @Version: V1.0
 */
@Api(tags="合作意向管理")
@RestController
@RequestMapping("/dbPurpose")
@Slf4j
public class DbPurposeController extends JeecgController<DbPurpose, IDbPurposeService> {
	@Autowired
	private IDbPurposeService dbPurposeService;


	/**
	 * 分页列表查询
	 *
	 * @param dbPurpose
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	//@AutoLog(value = "db_purpose-分页列表查询")
	@ApiOperation(value="分页列表查询合作意向", notes="分页列表查询合作意向")
	@GetMapping(value = "/list")
	public Result<IPage<DbPurpose>> queryPageList(DbPurpose dbPurpose,
								   @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
								   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
								   HttpServletRequest req) {
		QueryWrapper<DbPurpose> queryWrapper = QueryGenerator.initQueryWrapper(dbPurpose, req.getParameterMap());
		queryWrapper.orderByDesc("create_time");
		Page<DbPurpose> page = new Page<DbPurpose>(pageNo, pageSize);
		IPage<DbPurpose> pageList = dbPurposeService.page(page, queryWrapper);
		return Result.OK(pageList);
	}

	 /**
	  * 添加
 	  * @param dbPurpose
	  * @return
	  */
	 @AutoLog(value = "db_purpose-添加")
	@ApiOperation(value="添加合作意向", notes="添加合作意向")
	//@RequiresPermissions("org.jeecg.modules.demo:db_purpose:add")
	@PostMapping(value = "/add")
	public Result<String> add(@RequestBody DbPurpose dbPurpose) {
        dbPurposeService.add(dbPurpose);
		return Result.OK("添加成功！");
	}

	/**
	 *  编辑
	 *
	 * @param dbPurpose
	 * @return
	 */
	@AutoLog(value = "db_purpose-编辑")
	@ApiOperation(value="编辑合作意向", notes="编辑合作意向")
	//@RequiresPermissions("org.jeecg.modules.demo:db_purpose:edit")
	@RequestMapping(value = "/edit", method = {RequestMethod.PUT,RequestMethod.POST})
	public Result<String> edit(@RequestBody DbPurpose dbPurpose) {
		dbPurposeService.updateAndFileById(dbPurpose);
		return Result.OK("编辑成功!");
	}

	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "db_purpose-通过id删除")
	@ApiOperation(value="通过id删除合作意向", notes="通过id删除合作意向")
	//@RequiresPermissions("org.jeecg.modules.demo:db_purpose:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		dbPurposeService.deleteById(id);
		return Result.OK("删除成功!");
	}

	/**
	 *  批量删除
	 *
	 * @param ids
	 * @return
	 */
	@AutoLog(value = "db_purpose-批量删除")
	@ApiOperation(value="批量删除合作意向", notes="批量删除合作意向")
	//@RequiresPermissions("org.jeecg.modules.demo:db_purpose:deleteBatch")
	@DeleteMapping(value = "/deleteBatch")
	public Result<String> deleteBatch(@RequestParam(name="ids",required=true) String ids) {
		dbPurposeService.deleteBatch(ids);
		return Result.OK("批量删除成功!");
	}

	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	//@AutoLog(value = "db_purpose-通过id查询")
	@ApiOperation(value="通过id查询合作意向", notes="通过id查询合作意向")
	@GetMapping(value = "/queryById")
	public Result<DbPurposeVo> queryById(@RequestParam(name="id",required=true) String id) {
		DbPurposeVo dbPurposeVo=dbPurposeService.queryById(id);
		if (dbPurposeVo==null||dbPurposeVo.equals(null)){
			return Result.error("未查询到数据");
		}
		return Result.OK(dbPurposeVo);
	}

    /**
    * 导出excel
    *
    * @param request
    * @param dbPurpose
    */
    //@RequiresPermissions("org.jeecg.modules.demo:db_purpose:exportXls")
    @RequestMapping(value = "/exportXls")
    public ModelAndView exportXls(HttpServletRequest request, DbPurpose dbPurpose) {
        return super.exportXls(request, dbPurpose, DbPurpose.class, "db_purpose");
    }

    /**
      * 通过excel导入数据
    *
    * @param request
    * @param response
    * @return
    */
    //@RequiresPermissions("db_purpose:importExcel")
    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
        return super.importExcel(request, response, DbPurpose.class);
    }

}
